var redis = require("redis");
var redisConf = require("../conf/config")["redis"]["default"];

var client = redis.createClient(redisConf["port"],redisConf["host"],{auth_pass:redisConf["pass"]});

exports.set = function (key,value,cb) {
    client.on("ready",function (err) {
        if(err){
            console.error(err);
        }else {
            client.set(key, value, function (err,data) {
                if(err){
                    console.error(err);
                }else {
                    cb(data);
                }
            });
        }

    });
}

exports.get = function (key,cb) {
    client.on("ready",function (err) {
        if(err){
            console.error(err);
        }else {
            client.get(key,function (err,data) {
                if(err){
                    console.error(err);
                }else {
                    cb(JSON.parse(data));
                }
            });
        }
    });
}
